<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Initialize Element </title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<script language=javascript>
		function addChar(){
			var count=document.getElementById("elecount").value;
			var tb=document.getElementById("charTb");
			if(navigator.appName=="Microsoft Internet Explorer"){
				for(var i=0;i<count;i++){
				var tRow=tb.insertRow();
				var tCell=tRow.insertCell();
				tCell.innerHTML='<bean:message key="fullname"/>:<input type="text" name="eleWholeName"><bean:message key="shortname"/>:<input type="text" name="eleShortName">';
				}
			}else{
				for(var i=0;i<count;i++){
					tb.innerHTML+='<tr><td><bean:message key="fullname"/>:<input type="text" name="eleWholeName"><bean:message key="shortname"/>:<input type="text" name="eleShortName"></td></tr>';
				}
			}
		}
		function resetElement(tb){
			var tb=document.getElementById(tb);
			if(navigator.appName=="Microsoft Internet Explorer"){
				var childs=tb.childNodes;
				for(var i=0;i<childs.length;i++){
					tb.removeChild(childs[i]);
				}
			}else{
				tb.innerHTML="";
			}
			
		}
		function showSub(tb,img){
			var tb=document.getElementById(tb);
			var imgsrc=img.src;
			if(imgsrc.indexOf("open.jpg")!=-1){
				img.src="<%=path %>/images/close.jpg";
				tb.style.display="none";
			}else{
				img.src="<%=path %>/images/open.jpg";
				tb.style.display="";
			}
		}
		function addProp(){
			var count=document.getElementById("propcount").value;
			var tb=document.getElementById("propTb");
			if(navigator.appName=="Microsoft Internet Explorer"){
				for(var i=0;i<count;i++){
				var tRow=tb.insertRow();
				var tCell=tRow.insertCell();
				tCell.innerHTML='<bean:message key="fullname"/>:<input type="text" name="propWholeName"><bean:message key="shortname"/>:<input type="text" name="propShortName">';
				}
			}else{
				for(var i=0;i<count;i++){
					tb.innerHTML+='<tr><td><bean:message key="fullname"/>:<input type="text" name="propWholeName"><bean:message key="shortname"/>:<input type="text" name="propShortName"></td></tr>';
				}
			}
		}
		function addScene(){
			var count=document.getElementById("scenecount").value;
			var tb=document.getElementById("sceneTb");
			if(navigator.appName=="Microsoft Internet Explorer"){
				for(var i=0;i<count;i++){
				var tRow=tb.insertRow();
				var tCell=tRow.insertCell();
				tCell.innerHTML='<bean:message key="fullname"/>:<input type="text" name="sceneWholeName"><bean:message key="shortname"/>:<input type="text" name="sceneShortName">';
				}
			}else{
				for(var i=0;i<count;i++){
					tb.innerHTML+='<tr><td><bean:message key="fullname"/>:<input type="text" name="sceneWholeName"><bean:message key="shortname"/>:<input type="text" name="sceneShortName"></td></tr>';
				}
			}
		}
		function initElement(){
			var wchars=document.getElementsByName("eleWholeName");
			var schars=document.getElementsByName("eleShortName");
			var charResult=document.getElementById("charResult");
			charResult.value="";
			for(var i=0;i<wchars.length;i++){
				charResult.value+=wchars[i].value+","+schars[i].value+";";
			}
		
			
			var wprops=document.getElementsByName("propWholeName");
			var sprops=document.getElementsByName("propShortName");
			var propResult=document.getElementById("propResult");
			propResult.value="";
			for(var i=0;i<wprops.length;i++){
				propResult.value+=wprops[i].value+","+sprops[i].value+";";
			}
		
			
			var wscenes=document.getElementsByName("sceneWholeName");
			var sscenes=document.getElementsByName("sceneShortName");
			var sceneResult=document.getElementById("sceneResult");
			sceneResult.value="";
			for(var i=0;i<wscenes.length;i++){
				sceneResult.value+=wscenes[i].value+","+sscenes[i].value+";";
			}
		
			document.getElementById("form1").submit();
		}
	</script>
	<LINK href="styles/stylewang.css"  type=text/css rel=stylesheet>
    <style type="text/css">
<!--
.STYLE1 {
	font-family: "宋体";
	font-size: 12px;
}
-->
    </style>
</head>
  
  <body>
  	<center><b><bean:message key="initialize"/>&nbsp;<bean:message key="element"/></b></center><br>
  	<img src="<%=path %>/images/open.jpg" onClick="showSub('addChar',this);"><span class="STYLE1"><bean:message key="add"/>&nbsp;<bean:message key="character"/></span>
  <table id="addChar">
   		<tr>
   			<td id="rightbottom">
   				<input type="button" value="add character count" onClick="addChar();">
   				<input type="text" value="1" id="elecount">
   				<input type="button" value="<bean:message key='reset'/>" onClick="resetElement('charTb');">
   			</td>
   		</tr>
   		<tr>
   			<td><table id="charTb" class="rightbottom">
   				
   			</table></td>
   		</tr>
  </table>
   	<br>
   	<img src="<%=path %>/images/open.jpg" onClick="showSub('addProp',this);"><span class="STYLE1"><bean:message key="add"/>&nbsp;<bean:message key="prop"/></span>
   	<table id="addProp">
   		<tr>
   			<td id="rightbottom">
   				<input type="button" value="add prop count" onClick="addProp();">
   				<input type="text" value="1" id="propcount">
   				<input type="button" value="<bean:message key='reset'/>" onClick="resetElement('propTb');">
   			</td>
   		</tr>
   		<tr>
   			<td><table id="propTb" class="rightbottom">
   				
   			</table></td>
   		</tr>
   	</table>
   	<br>
   	<img src="<%=path %>/images/open.jpg" onClick="showSub('addScene',this);"><span class="STYLE1"><bean:message key="add"/>&nbsp;<bean:message key="sceneset"/></span>
   	<table id="addScene">
   		<tr>
   			<td id="rightbottom">
   				<input type="button" value="add scene count" onClick="addScene();">
   				<input type="text" value="1" id="scenecount">
   				<input type="button" value="<bean:message key='reset'/>" onClick="resetElement('sceneTb');">
   			</td>
   		</tr>
   		<tr>
   			<td><table id="sceneTb" class="rightbottom">
   				
   			</table></td>
   		</tr>
   	</table>
   	<form id="form1" action="<%=path %>/project/initElement.do" method=POST>
   		<input type="hidden" name="chars" id="charResult">
   		<input type="hidden" name="props" id="propResult">
   		<input type="hidden" name="scenes" id="sceneResult">
   		<input type="hidden" name="projectId" value="<%=request.getParameter("projectId") %>">
   		<input type="button" onClick="initElement();" value="<bean:message key='submit'/>">
   	</form>
  </body>
</html>
